package com.zr.gdms.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.gdms.service.CourseService;
import com.zr.gdms.serviceimpl.CourseServiceImpl;

public class AddScoreControllerZYH extends HttpServlet {
	CourseService cs = new CourseServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int sid = Integer.parseInt(req.getParameter("sid"));
		int score =Integer.parseInt(req.getParameter("score"));
		int month = 6, date1 = 5, date2 = 12;// 设置6月9日至12号为成绩录入时间
		Calendar c = Calendar.getInstance();
		int m = c.get(Calendar.MONTH) + 1;
		int d = c.get(Calendar.DATE);
		PrintWriter pw = resp.getWriter();
		if (m == month && d >= date1 && d <= date2) {
			if (cs.addScoreBySid(sid, score)==true) {
				pw.write("1");
			}else{
				pw.write("2");
			}
		}
		else{
			pw.write("0");
		}
		pw.flush();
		pw.close();
	}
}